<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>缓冲运动</title>
    <style>
        #div1{
            width: 100px;height: 100px;background: red;position: absolute;
            left: 0px; top: 50px;
        }
        #div2{
            width: 1px;
            height: 300px;
            position: absolute;
            left: 300px;
            background: black;
        }
    </style>
    <script>
        function startMove() {
            var oDiv = document.getElementById('div1');
            setInterval(function () {
                var speed = (300-oDiv.offsetLeft)/10;
                if (speed>0){
                    speed = Math.ceil(speed);
                }
                else {speed = Math.floor(speed);}
                oDiv.style.left=oDiv.offsetLeft+speed+'px';
                document.title = oDiv.offsetLeft;
            },30);

        }
    </script>
</head>
<body>
<input type="button" value="开始运动" onclick="startMove()">
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>